#include <algorithm>
#include <cctype>
#include <cstdio>
#define N 1000010
using namespace std;

struct Edge {
	int v, nxt, len;
} e[N << 1];
int heads[N], cnt;
inline void add(int u, int v, int le) {
	e[++cnt].v = v;
	e[cnt].nxt = heads[u];
	e[cnt].len = le;
	heads[u] = cnt;
}

inline int read() {
	int c = getchar(), res = 0;
	while (!isdigit(c))
		c = getchar();
	while (isdigit(c)) {
		res = (res << 1) + (res << 3) + c - '0';
		c = getchar();
	}
	return res;
}
int n, q;
int dep[N];
int fa[N][20];
int dis[N];
int lca(int x, int y) {
	if (dep[x] < dep[y]) {
		swap(x, y);
	}
	for (int i = 19; ~i; --i) {
		if (dep[fa[x][i]] >= dep[y]) {
			x = fa[x][i];
		}
	}
	if (x == y) {
		return x;
	}
	for (int i = 19; ~i; --i) {
		if (fa[x][i] != fa[y][i]) {
			x = fa[x][i];
			y = fa[y][i];
		}
	}
	return fa[x][0];
}
void dfs(int x) {
	for (int i = heads[x]; i; i = e[i].nxt) {
		if (e[i].v == fa[x][0])
			continue;
		dep[e[i].v] = dep[x] + 1;
		dis[e[i].v] = dis[x] + e[i].len;
		fa[e[i].v][0] = x;
		dfs(e[i].v);
	}
}
int main() {
	freopen("cows.in", "r", stdin);
	freopen("cows.out", "w", stdout);

	n = read();
	q = read();
	int tmp1, tmp2, tmp3;
	for (int i = 1; i < n; ++i) {
		tmp1 = read();
		tmp2 = read();
		tmp3 = read();
		add(tmp1, tmp2, tmp3);
		add(tmp2, tmp1, tmp3);
	}
	fa[1][0] = 1;
	dfs(1);
	for (int i = 1; i < 20; ++i)
		for (int j = 1; j <= n; ++j) {
			fa[j][i] = fa[fa[j][i - 1]][i - 1];
		}
	int a, b;
	for (int i = 0; i < q; ++i) {
		a = read();
		b = read();
		int faa = lca(a, b);
		printf("%d\n", dis[a] + dis[b] - 2 * dis[faa]);
	}
	fclose(stdin);
	fclose(stdout);
	return 0;
}